﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tools
{
    public class FileList
    {
        public FileList()
        {
            List = new List<CImgList>();
        }
        public List<CImgList> List { get; set; }
        public string ToString(string type)
        {
            if (type == "")
                return string.Join("\r\n",
                    List.Select(r => string.Join("\r\n", r.ImgList)));
            if (type == "json")
            {
                return Tools.JsonFormatTool.ConvertJsonString(Newtonsoft.Json.JsonConvert.SerializeObject(this));
            }

            return "FileList";
        }
        public static FileList JsonToFileList(string json)
        {
            try
            {
                FileList FL = Newtonsoft.Json.JsonConvert.DeserializeObject<FileList>(json);
                return FL;
            }
            catch
            {
            }
            return null;
        }
    }
    public class CImgList
    {
        public CImgList()
        {
            ImgList = new List<string>();
        }
        public string Path { get; set; }
        public List<string> ImgList { get; set; }
        public override string ToString()
        {
            string str =Path;
            if (str.Contains("\\"))
            {
                str = str.Substring(str.LastIndexOf("\\"));
            }
            if (str.Contains("."))
            {
                str = str.Substring(0, str.IndexOf("."));
            }
            if (str == "")
                return "未命名";
            return str;
        }
    }
}
